package com.jhws.business.customer.api;

import com.jhws.util.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/4/14.
 */
@Controller
@RequestMapping("/custom/web")
public class CustomWebApi {
    @Resource
    private RedisTemplate stringTemplate;

    /**
     * 返回小区广告页面给第三方
     * @return
     */
    @RequestMapping("outdoorImageAds")
    String outdoorImageAds() {
        return "redirect:/pages/3rdCustomer/outdoorImageAds/outdoor_advertisement.html";
    }

    /**
     * 返回IC发卡页面给第三方
     * @return
     */
    @RequestMapping("addCard")
    String addCard() {
        return "redirect:/pages/3rdCustomer/card/forSave.html";
    }

    /**
     * 返回IC发卡新页面给第三方
     * @return
     */
    @RequestMapping("saveCard")
    String saveCard() {
        return "redirect:/pages/business/card/forSave.html";
    }

    /**
     * 返回已发IC卡列表页面给第三方
     * @return
     */
    @RequestMapping("queryCard")
    String queryCard() {
        return "redirect:/pages/3rdCustomer/card/queryCard.html";
    }

    /**
     * 返回刷卡记录页面
     * @return
     */
    @RequestMapping("queryCardSwipedHistory")
    String queryCardSwipedHistory() {
        return "redirect:/card/queryBrushCard.x";
    }

    /**
     * 返回访客记录页面
     * @return
     */
    @RequestMapping("queryVisitors")
    String queryVisitors() {
        return "redirect:/VisitorCtrl/queryTblVisitor.x?page=1";
    }

    /**
     * 返回在线设备列表页面
     * @return
     */
    @RequestMapping("queryOnlineDevices")
    String queryOnlineDevices() {
        return "redirect:/pages/3rdCustomer/device/devicesList.html";
    }

    /**
     * 返回添加社区通知页面
     * @return
     */
    @RequestMapping("addNotice")
    String addNotice() {
        return "redirect:/NoticeCtrl/forSave.x" ;
    }

    /**
     * 返回查社区通知页面
     * @return
     */
    @RequestMapping("queryNotice")
    String queryNotice() {
        return "redirect:/NoticeCtrl/query.x";
    }

    /**
     * 业主列表页面
     * @return
     */
    @RequestMapping("queryOwner")
    String queryOwner() {
        return "redirect:/pages/business/owner/query.html";
    }

    /**
     * 管理员APP账号页面(废弃)
     * @return
     */
    @RequestMapping("queryManagerPhone")
    String queryManagerPhone() {
        return "redirect:/pages/business/manager/query.html";
    }

    /**
     * 小区信息页面(废弃)
     * @param webApiToken
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @RequestMapping("queryCommInfo")
    String queryCommInfo(String webApiToken) throws Exception {
        ValueOperations listOperations = stringTemplate.opsForValue();
        String commCode = (String) listOperations.get(webApiToken);
        if (StringUtils.isEmpty(commCode)) {
            return "redirect:/open/webApiError.x?httpStatus=401&errorInfo=没有可操作小区&content=哎哟喂！页面发生了错误！您无权限执行此操作！";
        }
        return "redirect:/comm/view.x?commCode=" + commCode;
    }
}
